package com.java.tutorials.spring.ProSpring4.ch6.springJdbcAnnotations;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.GenericXmlApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.sql.Date;


@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes= JdbcConfig.class)
public class AnnotationJdbcDaoSample {

    @Autowired
    ContactDao contactDao;

    @Test
    public void test(){
        Contact contact = new Contact();
        contact.setBirthDate(new Date(new java.util.Date().getTime()));
        contact.setFirstName("xu");
        contact.setLastName("zhike");
//        contactDao.insert(contact);
        contactDao.findAll();
        System.out.println(contactDao.findFirstNameById(1l));
    }

    public static void main(String[] args) {
        GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
        ctx.load("classpath:META-INF/spring/app-context-annotation.xml");
        ctx.refresh();

        ContactDao contactDao = ctx.getBean("contactDao", ContactDao.class);

        System.out.println(contactDao.findAll());
    }
}
